﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCT9.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        //从cookie获取当前的主题名GET/Home/index
        public ActionResult Index()
        {
            HttpCookie httpCookie = Request.Cookies["theme"] ?? new HttpCookie("theme", "default");
            ViewBag.Theme = httpCookie.Value;

            return View();
        }
        [HttpPost]
        //将当前的主题名保存到Cookie POST
        public ActionResult Index(string theme)
        {
            HttpCookie cookie = new HttpCookie("theme", theme);
            cookie.Expires = DateTime.MaxValue;
            Response.SetCookie(cookie);
            ViewBag.Theme = theme;
            return View();

        }
        //通过主题名获取CSS样式
        public ActionResult Css()
        {
            HttpCookie httpCookie = Request.Cookies["theme"] ?? new HttpCookie("theme", "default");
            switch (httpCookie.Value)
            {
                case "Theme1": return Content("body{font-family:SimHei;font-size:1.2em}", "text/css");
                case "Theme2": return Content("body{font-family:SimHei;font-size:1.2em}", "text/css");
                default:return Content("body{font-family:SimHei;font-size:1.2em}", "text/css");
            }
        }
    }
}